package com.jic.manager.impl;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.mapper.SensitiveMapper;
import com.jic.manager.entity.Sensitive;
import com.jic.conf.request.SensitiveRequest;
import com.jic.manager.service.SensitiveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 评论敏感词库表
 * @author :
 * @email :
 * @since : 2020-02-06 02:21:47
 * @version : v1.0.0
 */
@Service
public class SensitiveServiceImpl implements SensitiveService{

    @Autowired
    private SensitiveMapper sensitiveMapper;

    @Override
    public long insert(SensitiveRequest sensitive) {
        sensitive.setCreator(null!=sensitive.getAdminOperate()?sensitive.getAdminOperate().getOperator():0);
        sensitive.setCreatorName(null!=sensitive.getAdminOperate()?sensitive.getAdminOperate().getOperateName():"");
        long flag = sensitiveMapper.insert(sensitive);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return sensitiveMapper.delete(id);
    }

    @Override
    public long update(SensitiveRequest sensitive) {
        sensitive.setUpdater(null!=sensitive.getAdminOperate()?sensitive.getAdminOperate().getOperator():0);
        sensitive.setUpdaterName(null!=sensitive.getAdminOperate()?sensitive.getAdminOperate().getOperateName():"");
        return sensitiveMapper.update(sensitive);
    }

    @Override
    public Sensitive queryByPrimaryKey(Long id){
        return sensitiveMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<Sensitive> query(Sensitive sensitive){
        return sensitiveMapper.query(sensitive);
    }

    @Override
    public PageResult<Sensitive> queryPage(SensitiveRequest sensitiveRequest, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<Sensitive> list = sensitiveMapper.queryPage(startIndex, pageQuery.getLimit(),sensitiveRequest );
        long count = sensitiveMapper.queryPageCount(sensitiveRequest);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }
}